<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i> 后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>酒店用户评论管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="评分Id" width="80px" align="center"></el-table-column>
      <el-table-column prop="hotelName" label="酒店名字" width="200px"  align="center"
                       :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="hotelId" label="酒店Id" width="80px" align="center">
      </el-table-column>
      <el-table-column prop="username" label="用户名" width="200px" align="center"
                       :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="nickname" label="昵称" width="200px" align="center"
                       :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="userId" label="用户Id" width="80px" align="center">
      </el-table-column>
      <el-table-column prop="comment" label="用户评论" align="center"
                       :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete" circle size="mini"
                     @click="openDeleteConfirm(scope.row)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data(){
    return{
      tableData:[]
    }
  },
  methods: {
    loadUserCommentsList(){
      let url = 'http://localhost:9580/userComments/admin/getAdminUserCommentList';
      console.log("url"+url);
      this.axios
          .create({'headers':{'Authorization':localStorage.getItem('jwt')}})
          .get(url).then((response) =>{
        let responseBody=response.data;
        this.tableData=responseBody.data;
        console.log(this.tableData);
      })
    },
    openDeleteConfirm(item) {
      let message = '此操作将永久删除【' + item.username + '】对酒店【'+item.hotelName+'】的评论，是否继续？';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(item);
      }).catch(() => {
      });
    },
    handleDelete(item) {
      let url = 'http://localhost:9580/userComments/admin/'+item.id+'/deleteUserCommentById';
      console.log('url = ' + url);
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
          .post(url).then((response) => {
        let responseBody = response.data;
        if (responseBody.state == 20000) {
          this.$message({
            message: '删除评论数据成功！',
            type: 'success'
          });
          this.loadUserCommentsList();
        } else if (responseBody.state == 40400) {
          this.$alert(responseBody.message, '警告', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadUserScoreList();
            }
          });
        } else {
          this.$message.error(responseBody.message);
        }
      });
    }
  },
  mounted() {
    this.loadUserCommentsList();
  }
}
</script>

<style scoped>

</style>